from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-31 14:06:04.437560
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 31, Jan, 2022
Time: 14:06:09
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.9230
Nobs: 553.000 HQIC: -48.3510
Log likelihood: 6472.85 FPE: 7.62601e-22
AIC: -48.6253 Det(Omega_mle): 6.49005e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.348847 0.069688 5.006 0.000
L1.Burgenland 0.106607 0.042319 2.519 0.012
L1.Kärnten -0.110615 0.021982 -5.032 0.000
L1.Niederösterreich 0.197185 0.088503 2.228 0.026
L1.Oberösterreich 0.130789 0.087454 1.496 0.135
L1.Salzburg 0.254572 0.044730 5.691 0.000
L1.Steiermark 0.035428 0.058998 0.600 0.548
L1.Tirol 0.098129 0.047627 2.060 0.039
L1.Vorarlberg -0.071953 0.042088 -1.710 0.087
L1.Wien 0.018306 0.077845 0.235 0.814
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054671 0.150987 0.362 0.717
L1.Burgenland -0.041067 0.091690 -0.448 0.654
L1.Kärnten 0.040518 0.047627 0.851 0.395
L1.Niederösterreich -0.203966 0.191752 -1.064 0.287
L1.Oberösterreich 0.455364 0.189479 2.403 0.016
L1.Salzburg 0.283308 0.096913 2.923 0.003
L1.Steiermark 0.115761 0.127827 0.906 0.365
L1.Tirol 0.305922 0.103190 2.965 0.003
L1.Vorarlberg 0.023098 0.091189 0.253 0.800
L1.Wien -0.024088 0.168660 -0.143 0.886
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195111 0.035421 5.508 0.000
L1.Burgenland 0.090780 0.021510 4.220 0.000
L1.Kärnten -0.007409 0.011173 -0.663 0.507
L1.Niederösterreich 0.236119 0.044985 5.249 0.000
L1.Oberösterreich 0.168633 0.044451 3.794 0.000
L1.Salzburg 0.038443 0.022736 1.691 0.091
L1.Steiermark 0.025593 0.029988 0.853 0.393
L1.Tirol 0.080699 0.024208 3.334 0.001
L1.Vorarlberg 0.055465 0.021393 2.593 0.010
L1.Wien 0.118295 0.039567 2.990 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118135 0.035571 3.321 0.001
L1.Burgenland 0.043592 0.021601 2.018 0.044
L1.Kärnten -0.013791 0.011220 -1.229 0.219
L1.Niederösterreich 0.172044 0.045175 3.808 0.000
L1.Oberösterreich 0.335047 0.044640 7.506 0.000
L1.Salzburg 0.099694 0.022832 4.366 0.000
L1.Steiermark 0.109621 0.030115 3.640 0.000
L1.Tirol 0.090466 0.024311 3.721 0.000
L1.Vorarlberg 0.060672 0.021483 2.824 0.005
L1.Wien -0.015781 0.039735 -0.397 0.691
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125994 0.067132 1.877 0.061
L1.Burgenland -0.048160 0.040767 -1.181 0.237
L1.Kärnten -0.045488 0.021176 -2.148 0.032
L1.Niederösterreich 0.140601 0.085257 1.649 0.099
L1.Oberösterreich 0.166759 0.084246 1.979 0.048
L1.Salzburg 0.283982 0.043089 6.591 0.000
L1.Steiermark 0.058302 0.056834 1.026 0.305
L1.Tirol 0.155378 0.045880 3.387 0.001
L1.Vorarlberg 0.094135 0.040544 2.322 0.020
L1.Wien 0.071908 0.074989 0.959 0.338
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079841 0.052336 1.526 0.127
L1.Burgenland 0.023913 0.031782 0.752 0.452
L1.Kärnten 0.053323 0.016509 3.230 0.001
L1.Niederösterreich 0.192381 0.066467 2.894 0.004
L1.Oberösterreich 0.329767 0.065679 5.021 0.000
L1.Salzburg 0.033418 0.033593 0.995 0.320
L1.Steiermark 0.003819 0.044308 0.086 0.931
L1.Tirol 0.119845 0.035768 3.351 0.001
L1.Vorarlberg 0.066082 0.031609 2.091 0.037
L1.Wien 0.099398 0.058462 1.700 0.089
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174200 0.063287 2.753 0.006
L1.Burgenland 0.003555 0.038432 0.093 0.926
L1.Kärnten -0.065513 0.019963 -3.282 0.001
L1.Niederösterreich -0.110524 0.080374 -1.375 0.169
L1.Oberösterreich 0.215046 0.079421 2.708 0.007
L1.Salzburg 0.053170 0.040622 1.309 0.191
L1.Steiermark 0.250075 0.053579 4.667 0.000
L1.Tirol 0.498016 0.043252 11.514 0.000
L1.Vorarlberg 0.064660 0.038222 1.692 0.091
L1.Wien -0.079074 0.070694 -1.119 0.263
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156492 0.070027 2.235 0.025
L1.Burgenland -0.004162 0.042525 -0.098 0.922
L1.Kärnten 0.062145 0.022089 2.813 0.005
L1.Niederösterreich 0.181433 0.088933 2.040 0.041
L1.Oberösterreich -0.066041 0.087879 -0.752 0.452
L1.Salzburg 0.205239 0.044948 4.566 0.000
L1.Steiermark 0.139454 0.059285 2.352 0.019
L1.Tirol 0.056082 0.047858 1.172 0.241
L1.Vorarlberg 0.142814 0.042293 3.377 0.001
L1.Wien 0.129911 0.078223 1.661 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395679 0.040860 9.684 0.000
L1.Burgenland -0.002919 0.024813 -0.118 0.906
L1.Kärnten -0.020679 0.012889 -1.604 0.109
L1.Niederösterreich 0.202080 0.051891 3.894 0.000
L1.Oberösterreich 0.240928 0.051276 4.699 0.000
L1.Salzburg 0.033689 0.026226 1.285 0.199
L1.Steiermark -0.018040 0.034592 -0.521 0.602
L1.Tirol 0.087105 0.027925 3.119 0.002
L1.Vorarlberg 0.051144 0.024677 2.073 0.038
L1.Wien 0.034628 0.045642 0.759 0.448
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035331 0.103149 0.166706 0.133479 0.093965 0.082030 0.029615 0.212422
Kärnten 0.035331 1.000000 -0.025257 0.133388 0.046865 0.086253 0.444694 -0.068384 0.093324
Niederösterreich 0.103149 -0.025257 1.000000 0.310098 0.124533 0.268693 0.068202 0.156933 0.281654
Oberösterreich 0.166706 0.133388 0.310098 1.000000 0.215028 0.293016 0.170396 0.134213 0.236629
Salzburg 0.133479 0.046865 0.124533 0.215028 1.000000 0.124638 0.089571 0.103525 0.127298
Steiermark 0.093965 0.086253 0.268693 0.293016 0.124638 1.000000 0.135495 0.105918 0.030082
Tirol 0.082030 0.444694 0.068202 0.170396 0.089571 0.135495 1.000000 0.063296 0.151522
Vorarlberg 0.029615 -0.068384 0.156933 0.134213 0.103525 0.105918 0.063296 1.000000 -0.004906
Wien 0.212422 0.093324 0.281654 0.236629 0.127298 0.030082 0.151522 -0.004906 1.000000